package com.fone.player.activity.search.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.fone.player.R;
import com.fone.player.entity.PlayRecord;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class OnlinePlayListAdapter extends BaseAdapter {

	private Context mContext;
	private List<PlayRecord> mList;

	public OnlinePlayListAdapter(Context context, List<PlayRecord> list) {
		this.mList = list;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		int count = 0;
		if (mList != null) {
			count = mList.size();
		}
		return count;
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	ViewHolder viewHolder;

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.online_play_item, null);
			viewHolder = new ViewHolder();
		
			viewHolder.tv_time = (TextView) convertView
					.findViewById(R.id.tv_time);
			viewHolder.tv_content = (TextView) convertView
					.findViewById(R.id.tv_desc);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		PlayRecord record = mList.get(position);
		Date d = new Date(record.getPlayRecordCreateTime());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		String time=sdf.format(d);
		viewHolder.tv_time.setText(time);
		viewHolder.tv_content.setText(record.getPlayRecordName());
		return convertView;
	}

	static class ViewHolder {
		public TextView tv_time;
		public TextView tv_content;
	}
}
